package com.xhc.demo.dto;

import com.xhc.demo.entity.Order;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

public class OrderDTO {
    private Long orderId;
    private String orderNumber;
    private String payOrderNumber;
    private BigDecimal amount;
    private BigDecimal actualAmount;
    private Long userId;
    private LocalDateTime orderTime;
    private LocalDateTime paymentTime;
    private String status;
    
    // 地址信息
    private Long addressId;
    private String province;
    private String city;
    private String district;
    private String detailAddress;
    private String consignee;
    private String phoneNumber;

    // 照片信息
    private List<PhotoDTO> photos;

    public static OrderDTO fromEntity(Order order) {
        OrderDTO dto = new OrderDTO();
        dto.setOrderId(order.getOrderId());
        dto.setOrderNumber(order.getOrderNumber());
        dto.setPayOrderNumber(order.getPayOrderNumber());
        dto.setAmount(order.getAmount());
        dto.setActualAmount(order.getActualAmount());
        dto.setUserId(order.getUser() != null ? order.getUser().getUserId() : null);
        dto.setOrderTime(order.getOrderTime());
        dto.setPaymentTime(order.getPaymentTime());
        dto.setStatus(order.getStatus());
        
        // 设置地址信息
        if (order.getAddress() != null) {
            dto.setAddressId(order.getAddress().getAddressid());
            dto.setProvince(order.getAddress().getProvince());
            dto.setCity(order.getAddress().getCity());
            dto.setDistrict(order.getAddress().getDistrict());
            dto.setDetailAddress(order.getAddress().getDetailAddress());
            dto.setConsignee(order.getAddress().getConsignee());
            dto.setPhoneNumber(order.getAddress().getPhoneNumber());
        }

        // 设置照片信息
        if (order.getPhotos() != null) {
            dto.setPhotos(order.getPhotos().stream()
                    .map(PhotoDTO::fromEntity)
                    .collect(java.util.stream.Collectors.toList()));
        }
        
        return dto;
    }

    // Getters and Setters
    public Long getOrderId() {
        return orderId;
    }

    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }

    public String getOrderNumber() {
        return orderNumber;
    }

    public void setOrderNumber(String orderNumber) {
        this.orderNumber = orderNumber;
    }

    public String getPayOrderNumber() {
        return payOrderNumber;
    }

    public void setPayOrderNumber(String payOrderNumber) {
        this.payOrderNumber = payOrderNumber;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public BigDecimal getActualAmount() {
        return actualAmount;
    }

    public void setActualAmount(BigDecimal actualAmount) {
        this.actualAmount = actualAmount;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public LocalDateTime getOrderTime() {
        return orderTime;
    }

    public void setOrderTime(LocalDateTime orderTime) {
        this.orderTime = orderTime;
    }

    public LocalDateTime getPaymentTime() {
        return paymentTime;
    }

    public void setPaymentTime(LocalDateTime paymentTime) {
        this.paymentTime = paymentTime;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Long getAddressId() {
        return addressId;
    }

    public void setAddressId(Long addressId) {
        this.addressId = addressId;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getDistrict() {
        return district;
    }

    public void setDistrict(String district) {
        this.district = district;
    }

    public String getDetailAddress() {
        return detailAddress;
    }

    public void setDetailAddress(String detailAddress) {
        this.detailAddress = detailAddress;
    }

    public String getConsignee() {
        return consignee;
    }

    public void setConsignee(String consignee) {
        this.consignee = consignee;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public List<PhotoDTO> getPhotos() {
        return photos;
    }

    public void setPhotos(List<PhotoDTO> photos) {
        this.photos = photos;
    }
}
